[root@linux1 ~]# date Sun Feb 15 04:43:02 IST 2015 [root@linux1 ~]# cal 2012 2012 January February March Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 1 2 3 4 1 2 3 8 9 10 11 12 13 14 5 6 7 8 9 10 11 4 5 6 7 8 9 10 15 16 17 18 19 20 21 12 13 14 15 16 17 18 11 12 13 14 15 16 17 22 23 24 25 26 27 28 19 20 21 22 23 24 25 18 19 20 21 22 23 24 29 30 31 26 27 28 29 25 26 27 28 29 30 31 April May June Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 1 2 3 4 5 1 2 8 9 10 11 12 13 14 6 7 8 9 10 11 12 3 4 5 6 7 8 9 15 16 17 18 19 20 21 13 14 15 16 17 18 19 10 11 12 13 14 15 16 22 23 24 25 26 27 28 20 21 22 23 24 25 26 17 18 19 20 21 22 23 29 30 27 28 29 30 31 24 25 26 27 28 29 30 July August September Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 7 1 2 3 4 1 8 9 10 11 12 13 14 5 6 7 8 9 10 11 2 3 4 5 6 7 8 15 16 17 18 19 20 21 12 13 14 15 16 17 18 9 10 11 12 13 14 15 22 23 24 25 26 27 28 19 20 21 22 23 24 25 16 17 18 19 20 21 22 29 30 31 26 27 28 29 30 31 23 24 25 26 27 28 29 30 October November December Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa Su Mo Tu We Th Fr Sa 1 2 3 4 5 6 1 2 3 1 7 8 9 10 11 12 13 4 5 6 7 8 9 10 2 3 4 5 6 7 8 14 15 16 17 18 19 20 11 12 13 14 15 16 17 9 10 11 12 13 14 15 21 22 23 24 25 26 27 18 19 20 21 22 23 24 16 17 18 19 20 21 22 28 29 30 31 25 26 27 28 29 30 23 24 25 26 27 28 29 30 31 [root@linux1 ~]# who root pts/1 2015-02-15 04:23 (192.16.1.1) [root@linux1 ~]# who -b system boot 2015-02-14 19:44 [root@linux1 ~]# uptime 05:01:16 up 9:17, 1 user, load average: 0.00, 0.04, 0.16 *----------------------------------------------------------------------------------------------* uptime : The current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes. *-----------------------------------------------------------------------------------------------* [root@linux1 ~]# pwd root [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop install.log install.log.syslog murugappan output.html output.sh sam.sh [root@linux1 ~]# ls -l total 124 -rw-r--r-- 1 root DBA 139 Dec 16 2011 \ -rw------- 1 root DBA 875 Mar 6 2011 anaconda-ks.cfg -rwxr-xr-x 1 root DBA 2526 Mar 19 2012 dailymon_KAR_20120319.html -rwxrwxrwx 1 root DBA 43814 Mar 19 2012 dba_database_10g.sql drwxr-xr-x 3 root DBA 4096 Mar 6 2011 Desktop -rw-r--r-- 1 root DBA 29961 Mar 6 2011 install.log -rw-r--r-- 1 root DBA 3686 Mar 6 2011 install.log.syslog drwxr-xr-x 2 root DBA 4096 Feb 15 04:24 murugappan -rw-r--r-- 1 root DBA 284 Feb 14 19:55 output.html -rw-r--r-- 1 root DBA 284 Feb 14 19:52 output.sh -rw-r--r-- 1 root DBA 36 Feb 15 2015 sam.sh [root@linux1 ~]# *----------------------------------------------------------------------------------------------* -rw-r--r-- -> If it starts with - its mean that file is in root directory drwxr-xr-x -> If it starts with d its mean that file is in any other directory 1 (or) 3 -> root -> owner name DBA -> Group name 139 -> Dec 16 2011 -> File created Date Month Year anaconda-ks.cfg -> File_name.extension File Permission : r : Read w : Write x : Execute rwxrwxrwx ---***^^^ --- Owner permission *** Group permission ^^^ other users (Members not in group) permission r : 4 w : 2 x : 1 7 : All permission drwxrwxrwx : Full permission (777) -rw-r--r-- : Partial permission (644) *-----------------------------------------------------------------------------------------------* chmod : changes the access mode of one file or multiple files. chmod : One file [root@linux1 murugappan]# ls [root@linux1 murugappan]# cat >first.txt cat ->display 1 2 [root@linux1 murugappan]# ls -l total 4 -rw-r--r-- 1 root root 4 Feb 15 06:10 first.txt [root@linux1 murugappan]# chmod 677 first.txt [root@linux1 murugappan]# ls -l total 4 -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt chmod -R : [root@linux1 murugappan]# ls -l total 4 -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt [root@linux1 murugappan]# chmod -R 777 first.txt [root@linux1 murugappan]# ls -l total 4 -rwxrwxrwx 1 root root 4 Feb 15 06:10 first.txt *-----------------------------------------------------------------------------------------------* Users are organized into groups, every users is in at least one group, and may be in other groups. Group membership gives you special access to files and directories which are permitted to that group. To view all the groups available in unix : less /etc/group (click Q to quit) To create a group : groupadd group_name Ex : groupadd mba *-----------------------------------------------------------------------------------------------* [root@linux1 murugappan]# less /etc/group root:x:0:root bin:x:1:root,bin,daemon daemon:x:2:root,bin,daemon sys:x:3:root,bin,adm adm:x:4:root,adm,daemon tty:x:5: disk:x:6:root lp:x:7:daemon,lp [root@linux1 ~]# groupadd mba [root@linux1 ~]# useradd murugappan -g mba [root@linux1 ~]# chown murugappan:mba testfile2.sql; [root@linux1 ~]# chown -R murugappan:mba file3.sql; *-----------------------------------------------------------------------------------------------* ls -> List all the files in the current directory ls -l -> List all the files with all details ls -la -> List all the files with hidden files (Hidden file name starts with .[dot]) ls -lt -> sort file in desending order based on time & Date ls -ltr -> sort file in assending order based on time & Date *-----------------------------------------------------------------------------------------------* [root@linux1 murugappan]# cat > .myhidfile [root@linux1 murugappan]# ls f1il1.sql f1il2.sql first.txt [root@linux1 murugappan]# ls -l total 8 -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql 44 -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt [root@linux1 murugappan]# ls -la total 20 drwxr-xr-x 2 root root 4096 Feb 15 07:28 . drwxr-x--- 18 root root 4096 Feb 15 06:08 .. -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt -rw-r--r-- 1 root root 0 Feb 15 07:28 .myhidfile [root@linux1 murugappan]# ls -lt total 8 -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt [root@linux1 murugappan]# ls -ltr total 8 -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql *-----------------------------------------------------------------------------------------------* pwd Present working directory cat > file_name.extension To create a file Type your content CTRL + D To save the file cat file_name To display the file more file_name Its only used to display the content of the file [If you open the file in VI editor or cat you can edit the file] *-----------------------------------------------------------------------------------------------* [root@linux1 murugappan]# pwd /root/murugappan *-----------------------------------------------------------------------------------------------* Tools used to edit the file : cat vi touch cat & vi : by using this we can create and edit the file touch : we can only create the file using this editor [If you want to edit you can use cat or vi editor] By using touch we can create more than one file at a time [If you create 5 file in same time by using touch means all timestamp value will be same] we have 10 pages in the document - VI Editor : Display the first page cat : Display the last page of file VI Editor : Append happen at any line Cat : Append Happen only at end of the file *-----------------------------------------------------------------------------------------------* [root@linux1 murugappan]# cat > jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix CTRL+D [root@linux1 murugappan]# cat jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix [root@linux1 murugappan]# more jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix [root@linux1 murugappan]# vi jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix ~ ~ ~ [root@linux1 murugappan]# cat jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix [root@linux1 murugappan]# cat >> jeni.txt Raj:Jeni:john [root@linux1 murugappan]# cat jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | grep john john:murugan:brito Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | grep -e john -e Felix john:murugan:brito Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | grep -e john -e Felix | grep -v brito Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | grep -v ravi john:murugan:brito Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | grep -v Ravi john:murugan:brito Karthi:Emil:Felix Raj:Jeni:john *-----------------------------------------------------------------------------------------------* wc : word count wc -l line wc -c bytes wc file_name.extension wc filename o/p : X Y Z filename X – Number of lines Y – Number of words Z – Number of bytes filename – name of the file *-----------------------------------------------------------------------------------------------* [root@linux1 murugappan]# more jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# more jeni.txt | wc -l 4 [root@linux1 murugappan]# more jeni.txt | wc -c 70 [root@linux1 murugappan]# wc jeni.txt 4 4 70 jeni.txt [root@linux1 murugappan]# cat >number.txt 1 2 3 4 5 6 7 8 9 10 [root@linux1 murugappan]# cat number.txt 1 2 3 4 5 6 7 8 9 10 [root@linux1 murugappan]# head -3 number.txt 1 2 3 [root@linux1 murugappan]# tail -3 number.txt 8 9 10 [root@linux1 murugappan]# head -5 number.txt | tail -2 4 5 [root@linux1 murugappan]# cat jeni.txt john:murugan:brito Ravi:Raj:Kumar Karthi:Emil:Felix Raj:Jeni:john [root@linux1 murugappan]# cat jeni.txt | cut -d ':' -f2 murugan Raj Emil Jeni [root@linux1 murugappan]# cat jeni.txt | cut -d ':' -f3 brito Kumar Felix john [root@linux1 murugappan]# more jeni.txt | awk -F: '{print $2}' murugan Raj Emil Jeni [root@linux1 murugappan]# more jeni.txt | awk -F: '{ print $3 }' brito Kumar Felix john [root@linux1 murugappan]# more jeni.txt | awk -F: '{ print "Name : " $3 }' Name : brito Name : Kumar Name : Felix Name : john [root@linux1 murugappan]# ls -l total 16 -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt -rw-r--r-- 1 root root 70 Feb 15 07:55 jeni.txt -rw-r--r-- 1 root root 21 Apr 9 14:24 number.txt [root@linux1 murugappan]# ls -l | awk '{ print $9}' f1il1.sql f1il2.sql first.txt jeni.txt number.txt [root@linux1 murugappan]# ls -l total 16 -rw-r--r-- 1 root root 25 Feb 15 06:27 f1il1.sql -rw-r--r-- 1 root root 0 Feb 15 06:28 f1il2.sql -rw-rwxrwx 1 root root 4 Feb 15 06:10 first.txt -rw-r--r-- 1 root root 70 Feb 15 07:55 jeni.txt -rw-r--r-- 1 root root 21 Apr 9 14:24 number.txt [root@linux1 murugappan]# ls -l | grep -e Apr -e 70 | awk '{print $9}' jeni.txt number.txt [root@linux1 murugappan]# ls f1il1.sql f1il2.sql first.txt jeni.txt number.txt [root@linux1 murugappan]# rm -fr number.txt [root@linux1 murugappan]# ls f1il1.sql f1il2.sql first.txt jeni.txt [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop install.log install.log.syslog murugappan output.html output.sh sam.sh testfile [root@linux1 ~]# mkdir dir_to_del; [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop dir_to_del install.log install.log.syslog murugappan output.html output.sh sam.sh testfile [root@linux1 ~]# rmdir dir_to_del [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop install.log install.log.syslog murugappan output.html output.sh sam.sh testfile [root@linux1 ~]# [root@linux1 murugappan]# ls f1il1.sql f1il2.sql first.txt jeni.txt [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop install.log install.log.syslog murugappan output.html output.sh sam.sh testfile [root@linux1 ~]# \rm murugappan/jeni.txt [root@linux1 ~]# ls \ anaconda-ks.cfg dailymon_KAR_20120319.html dba_database_10g.sql Desktop install.log install.log.syslog murugappan output.html output.sh sam.sh testfile [root@linux1 ~]# \rm murugappan/* [root@linux1 ~]# cd murugappan [root@linux1 ~]#rm -fr *.txt [root@linux1 murugappan]# ls 1.txt 2.txt 3.txt [root@linux1 murugappan]# gzip 3.txt [root@linux1 murugappan]# ls 1.txt 2.txt 3.txt.gz [root@linux1 murugappan]# gunzip 3.txt [root@linux1 murugappan]# ls 1.txt 2.txt 3.txt [root@linux1 murugappan]# ls 1.txt 2.txt 3.txt [root@linux1 murugappan]# mv 3.txt three.txt [root@linux1 murugappan]# ls 1.txt 2.txt three.txt [root@linux1 murugappan]# pwd /root/murugappan [root@linux1 murugappan]# mv three.txt /root/murugan/ [root@linux1 murugappan]# ls 1.txt 2.txt [root@linux1 murugappan]# cd .. [root@linux1 ~]# cd murugan [root@linux1 murugan]# ls three.txt [root@localhost etc]# ls /etc [root@localhost murugan]# rm -fr *.txt Too many arguments If we have more than 1024 files in this location means it will throug you the error due to less memory space rm -fr 1.txt 2.txt 3.txt 4.txt So we are going to use the following method [root@localhost murugan]# ls 1.txt 2.txt 3.txt 4.txt [root@localhost murugan]# ls -l total 0 -rw-r--r-- 1 root root 0 May 26 05:25 1.txt -rw-r--r-- 1 root root 0 May 26 05:25 2.txt -rw-r--r-- 1 root root 0 May 26 05:25 3.txt -rw-r--r-- 1 root root 0 May 26 05:25 4.txt [root@localhost murugan]# ls -l | awk '{print $9}' 1.txt 2.txt 3.txt 4.txt [root@localhost murugan]# ls -l | awk '{print "rm -fr " $9}' rm -fr rm -fr 1.txt rm -fr 2.txt rm -fr 3.txt rm -fr 4.txt [root@localhost murugan]# ls -l | awk '{print "rm -fr " $9}' | sh -x + rm -fr + rm -fr 1.txt + rm -fr 2.txt + rm -fr 3.txt + rm -fr 4.txt [root@localhost murugan]# ls [root@localhost murugan]# [root@localhost murugan]# ps PID TTY TIME CMD 3554 pts/1 00:00:00 bash 3671 pts/1 00:00:00 su 3672 pts/1 00:00:00 bash 5943 pts/1 00:00:00 ps [root@localhost murugan]# kill 3671 Session terminated, killing shell...[root@localhost murugan]# ...killed. You have new mail in /var/spool/mail/root [root@localhost murugan]# PID TTY TIME CMD 3554 pts/1 00:00:00 bash 5945 pts/1 00:00:00 ps [root@localhost murugan]#